import { defineStore } from 'pinia'
import { ref } from 'vue'

interface Article {
  id: string;
  title: string;
  content: string;
  author: string;
  authorId: string;
  createdAt: string;
  updatedAt: string;
  tags: string[];
  coverImage?: string;
}

export const useArticleStore = defineStore('article', () => {
  // 文章列表
  const articleList = ref<Article[]>([])
  
  // 文章总数
  const total = ref(0)
  
  // 当前页
  const currentPage = ref(1)
  
  // 每页数量
  const pageSize = ref(10)
  
  // 加载状态
  const loading = ref(false)
  
  // 设置文章列表
  function setArticleList(list: Article[]) {
    articleList.value = list
  }
  
  // 设置分页信息
  function setPagination(pageInfo: { total: number, currentPage: number, pageSize: number }) {
    total.value = pageInfo.total
    currentPage.value = pageInfo.currentPage
    pageSize.value = pageInfo.pageSize
  }
  
  // 设置加载状态
  function setLoading(status: boolean) {
    loading.value = status
  }
  
  return {
    articleList,
    total,
    currentPage,
    pageSize,
    loading,
    setArticleList,
    setPagination,
    setLoading
  }
}) 